const CONFIG = require('../../config.js');
Page({
	data: {
		navBgColor: '-webkit-gradient(linear, 0% 0%, 0% 100%,from(#1b64e5), to(#488dea))',
		userData: null
	},

	// 拨打电话
	phoneCall(e){
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.phone,
			success: function () {
				console.log("成功拨打电话")
			},
		})
	},
	
	// 获取联系人列表信息
	getUserData(id){
		wx.request({
			url: CONFIG.host + "/system/salesmanController/getSalesmanListForAPP",
			data: {},
			method: "GET",
			header: {
				'content-type': 'application/json',
				'Authorization': this.data.loginInfo.token
			},
			success: res => {
				if(res.data.code === 'success'){
					let datas = res.data.data;
						datas.forEach((ele,index)=>{
							if(ele.avatar){
								ele.avatar = 'https://wx.huidailang.cn/prod-api' + ele.avatar;
							}
						})
						this.setData({
						userData : datas
					})
				}
			},fail: function (error) {
				console.log(error);
			}
		})
	},
	onLoad: function () {
		let loginInfo = wx.getStorageSync('loginInfo') || '';
		if(loginInfo){
			this.setData({
				loginInfo : JSON.parse(loginInfo)
			})
			this.getUserData();
		}
	}
})
